import apiDouBaoVoice from '@/api/modules/doubaoVoice'

export const useDouBaoVoiceStore = defineStore(
  // 唯一ID
  'douBaoVoice',
  () => {

    const douBaoVoiceAppId = ref(localStorage.douBaoVoiceAppId ?? '')
    const douBaoVoiceAccessToken = ref(localStorage.douBaoVoiceAccessToken ?? '')
    const douBaoVoiceResourceId = ref(localStorage.douBaoVoiceResourceId ?? '')
    const isConfig = computed(() => {
      if (douBaoVoiceAccessToken) {
        return true
      }
      return false
    })

    async function submitTask(data: any) {
      // 填充appid属性
      data.appid = douBaoVoiceAppId.value
      return await apiDouBaoVoice.submitTask(data)
    }

    async function queryTask(taskId: string) {
      return await apiDouBaoVoice.queryTask(douBaoVoiceAppId.value, taskId)
    }

    return {
      douBaoVoiceAppId,
      douBaoVoiceAccessToken,
      douBaoVoiceResourceId,
      isConfig,
      submitTask,
      queryTask
    }
  },
)
